get_foto();
function get_foto(){
	//var foto_pro;
	var url_img1;
	$.post(host+"backend/get_data/foto/"+user_id,function(r){
		url_img1=host+'repositori/user_profil/'+r;
		console.log(url_img1);
		$('#foto_na').attr("src",url_img1+'?timestamp='+ new Date().getTime());	
	});
	
}
$('#list_produk').datagrid({
				title:'List Pemesanan Email',
				//iconCls:'icon-ok',
				width:lebar-572,
				height:tinggi-255,
				nowrap: false,
				singleSelect:true,
				autoRowHeight: false,
				striped: true,
				collapsible:false,
				url: host+'backend/get_data/tbl_pesan_email/all',
				pagination:"true",
				queryParams:{
					user_id:user_id,
					user_group:user_group
				},
				
				rowStyler: function(index,row){
					if (row.flag ==1){
						return 'background-color:#C1272D;color:#F7F7F7;font-weight:bold;';
					}
					
				},
				
			toolbar:[
					
					 {
						text:'Selesai Cetak',
						iconCls:'icon-ok',
						handler:function(){
							cek_grid('edit','Edit Data Reseller Produk');
						}
					
					 },'-',
					 {
						text:'Hapus',
						iconCls:'delete',
						handler:function(){
							cek_grid('delete','Hapus Data Reseller Produk');
						}
					 }
					 
				
			],	
			frozenColumns:[[
				{field:'ck', checkbox:true},
				{field:'foto_1' ,title:'Design/Produk', width:150, sortable:true,align:'center'
					,formatter:function(value,rowData,rowindex){
						if(rowData.design==null){
						 return '<img src="'+host+'repositori/produk_user/'+value+'" id="gambar_1" height="100" width="100" class="gambar_kecil">';
						}
						else{
						 return '<img src="'+host+'repositori/cetak_sendiri/'+rowData.design+'" id="gambar_1" height="100" width="100" class="gambar_kecil">';
						}
					}
				}
				
			]],
				columns:[[
					{field:'nama_produk' ,title:'Nama Produk', width:170, sortable:true
					,formatter:function(value,rowData,rowindex){
						if(rowData.design==null){
							return value;
						}
						else{return 'Cetak Design Sendiri';}
					}
				},
					{field:'nama' ,title:'Nama Pemesan', width:120, sortable:true},
					{field:'jml' ,title:'Jml.Pesan', width:80, sortable:true,align:'right'},
					{field:'alamat' ,title:'Alamat', width:250, sortable:true},
					{field:'telp' ,title:'Telp', width:80, sortable:true,align:'right'},
					{field:'hp' ,title:'HP', width:80, sortable:true},
					{field:'comment' ,title:'Komen', width:250, sortable:true},
					
					
				]]
});

function cek_grid(tbl,jdl){
		row = $('#list_produk').datagrid('getSelected');
		if(row){
			if(tbl=='delete'){
				$.messager.confirm('Confirm','Yakin Data Ini Akan Dihapus ?',function(r){  
					if (r==true){  
					  	$.post(host+'backend/hapus/tbl_pesan_email',{id:row.id,design:row.design},function(resp){
							if(resp==1){$.messager.alert("Data","Data Sudah Terhapus",'info');$('#list_produk').datagrid('reload');}		   
						});	
					}  
				}); 
			}
			else{
				$.post(host+'backend/set_flag',{id:row.id,flag:2},function(resp){
							if(resp==1){$.messager.alert("Data","Pemesanan Produk Selesai",'info');$('#list_produk').datagrid('reload');}		
				});
			}
		}
		else{$.messager.alert("Data","Pilih Salah Satu Data",'error');}
}

$('#btn').bind('click',function(){
				//loadingna();
				jQuery('#form_profil').form('submit',{
					url:host+'backend/simpan/tbl_user',
					onSubmit: function(){
						  return $('#form_profil').form('validate');
					},
					success:function(r){
						
						if(r==1){						
							$.messager.alert("Simpan Data","Data Sudah Tersimpan",'info');
							get_foto();
						}
						else{
							console.log(r);
							$.messager.alert("Simpan Data","Data Gagal Tersimpan",'error');
							
						}
						 
					},
					
					error:function(data){
						console.log(r);
						 $.messager.alert("Simpan Data","Data Gagal Tersimpan",'error');
						// winLoadingClose();
						
					}
				});
		  });